Skip to main content

Rewarded

Rewarded ads (also known as rewarded video ads) are a fullscreen format, but unlike interstitials the user is incentivized to watch its entire duration (usually 30 seconds) in order to get an in-app reward, such as in-game currency, extra lives or hints to pass a level.

The onEarnedReward (or equivalent) callback will be triggered by the adapted network, signaling that you can give the user their reward. If the user decides to skip the ad, this callback will not be called.

Start loading an ad

import XMediator

XMediatorAds.startWith(appKey: "<your-app-key>") { result in
XMediatorAds.rewarded.load(placementId: "<placement-id>")
}

Presenting an ad

Calling isReady() will return if there's a rewarded ad available to be shown, regardless of its placement id. If multiple ads with different placement ids were previously loaded, the SDK will try to show the best one available.

if XMediatorAds.rewarded.isReady() {
XMediatorAds.rewarded.present(fromViewController: self, fromAdSpace: "rewarded-ad-space")
}

Presenting an ad with placementId

When the app needs to present an ad for a specific placement id, isReady(withPlacementId:) and present(withPlacementId:) can be alternatively used.

if XMediatorAds.rewarded.isReady(withPlacementId: "<placement-id>") {
XMediatorAds.rewarded.present(withPlacementId: "<placement-id>", fromViewController: self, fromAdSpace: "rewarded-ad-space")
}

Built-in features

Auto loading

Dismissed or failed to show ads will automatically trigger a new load request.

Auto retry

Failed to load ads will make a retry attempts, with an exponential backoff.

Additional settings

Register ad callbacks

Every ad callback indicates the placement id of the rewarded ad that triggered the event.

// Assign a delegate to handle the ad callbacks
XMediatorAds.rewarded.addDelegate(self)

// [...]

func didLoad(placementId: String, result: LoadResult) {
print("Rewarded loaded! placementId: \(placementId)")
}

func didPresent(placementId: String) {
print("Rewarded is being presented! placementId: \(placementId)")
}

func failedToPresent(placementId: String, error: PresentError) {
// If you need to resume your app's flow, make sure to do it here and in the didDismiss callback
print("Rewarded failed to present. placementId: \(placementId), Reason: \(error.localizedDescription)")
}

func didRecordImpression(placementId: String, data: ImpressionData) {
print("Rewarded impression, with revenue: \(data.revenue). placementId: \(placementId)")
}

func willDismiss(placementId: String) {
print("Rewarded will be dismissed! placementId: \(placementId)")
}

func didDismiss(placementId: String) {
// If you need to resume your app's flow, make sure to do it here and in the failedToPresent callback
print("Rewarded dismissed! placementId: \(placementId)")
}

func didClick(placementId: String) {
print("Rewarded clicked! placementId: \(placementId)")
}

// Reward Callback
func didEarnReward(placementId: String) {
print("Rewarded ad earned a reward! placementId: \(placementId)")
}

Code example

In addition to the example below, you can see a real implementation in our iOS Demo App.

RewardedViewController.swift
import UIKit
import XMediator

class RewardedViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}

@IBAction func startButtonTouchUpInside(_ sender: Any) {
XMediatorAds.startWith(appKey: "<your-app-key>") { result in
XMediatorAds.rewarded.addDelegate(self)

// Start loading a rewarded ad. Subsequent loads or retries are handled by the sdk
XMediatorAds.rewarded.load(placementId: "<placement-id>")
}
}

@IBAction func presentButtonTouchUpInside(_ sender: Any) {
if XMediatorAds.rewarded.isReady() {
XMediatorAds.rewarded.present(fromViewController: self)
}
}
}

extension RewardedViewController: RewardedAdsDelegate {
func didLoad(placementId: String, result: LoadResult) {
print("Rewarded loaded! placementId: \(placementId)")
}

func didPresent(placementId: String) {
print("Rewarded is being presented! placementId: \(placementId)")
}

func failedToPresent(placementId: String, error: PresentError) {
// If you need to resume your app's flow, make sure to do it here and in the didDismiss callback
print("Rewarded failed to present. placementId: \(placementId), Reason: \(error.localizedDescription)")
}

func didRecordImpression(placementId: String, data: ImpressionData) {
print("Rewarded impression, with revenue: \(data.revenue). placementId: \(placementId)")
}

func willDismiss(placementId: String) {
print("Rewarded will be dismissed! placementId: \(placementId)")
}

func didDismiss(placementId: String) {
// If you need to resume your app's flow, make sure to do it here and in the failedToPresent callback
print("Rewarded dismissed! placementId: \(placementId)")
}

func didClick(placementId: String) {
print("Rewarded clicked! placementId: \(placementId)")
}

func didEarnReward(placementId: String) {
print("Rewarded ad earned a reward! placementId: \(placementId)")
}
}